package gui;

import processing.core.PApplet;

public class PlayButton extends Widget {
	// Widget that implements a play/pause button
	
	boolean play;

	public PlayButton(PApplet parent_applet, float[] r, Object... args) {
		super(parent_applet, r, args);
		// PlayButton initialises in the pause state.
	    play = false;
	}
	
	public void mouseClicked() {
		// If mouse is clicked, switch play button state
		// Should only do this if the actual play button is clicked,
		// but currently responds to any mouse click.
 		play = !play;
	}

	public boolean isPlay() {
		// getter for current button state.
		return play;
	}

	public void draw() {
		pa.fill(0, 0, 0);
        pa.rect(x0, y0, width, height);

        pa.fill(255, 255, 255);
		if (play) {
			// If in the play state, draw a pause symbol
			float x1 = (float) (x0 + width/5.);
			float y1 = (float) (y0 + height/5.);
            pa.rect(x1, y1, (float)(width/5.), (float)(3.*height/5.));
			float x2 = (float) (x0 + 3.*width/5.);
			float y2 = (float) (y0 + height/5.);
            pa.rect(x2, y2, (float)(width/5.), (float)(3.*height/5.));
		} 
		else {
			// If in the pause state, draw a play symbol
			float x1 = x0 + width/5;
			float x2 = x0 + width/5;
			float x3 = x0 + 4*width/5;
			float y1 = y0 + height/5;
			float y2 = y0 + 4*height/5;
			float y3 = y0 + height/2;
            pa.triangle(x1, y1, x2, y2, x3, y3);
		}
	}

}
